import config from '@/common/config';

import user from './modules/user';
import article from './modules/article';

export let baseRouterMap = [
  {
    path: '/login',
    name: 'Login',
    component: resolve => require(['@/pages/Login/Login.vue'], resolve)
  },
  {
    path: '/error',
    name: 'Error',
    component: resolve => require(['@/layout/layout/index.vue'], resolve),
    children: [
      {
        path: '/404',
        name: ' 404',
        component: resolve => require(['@/pages/404/index.vue'], resolve)
      },
      {
        path: '/500',
        name: '500',
        component: resolve => require(['@/pages/500/index.vue'], resolve)
      }
    ]
  }
];
// 权限验证后的路由
export const asyncRouterMap = [
  article,
  user,
  {
    path: '*',
    redirect: '/login'
  }
];

let isAuthentication = config.menu.isAuthentication;

if (process.env.NODE_ENV !== 'development') {
  isAuthentication = true;
}

if (!isAuthentication) {
  baseRouterMap = baseRouterMap.concat(asyncRouterMap);
}

console.log(baseRouterMap);

// 路由的模式 只支持 'history' || 'hash'
let ROUTER_MODE = process.env.HISTORY || 'history';
export default {
  mode: ROUTER_MODE,
  base: '/oa',
  scrollBehavior: () => ({
    y: 0
  }),
  routes: baseRouterMap
};
